package opera1;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{

    @Override
    public void work(BookList bookList) {
        Scanner input = new Scanner(System.in);
        int currentUsedSize = bookList.getUsedSize();
        System.out.println("请输入书名:");
        String bookName = input.nextLine();
        System.out.println("请输入作者:");
        String autor = input.nextLine();
        System.out.println("请输入价格:");
        int price = input.nextInt();
        input.nextLine();
        System.out.println("请输入类型:");
        String type = input.nextLine();

        Book addBook = new Book(bookName,autor,price,type);

        for (int i = 0; i < currentUsedSize ; i++) {
            Book book = bookList.getBook(i);
            if (bookName.equals(book.getName())) {
                System.out.println("已经有这本书了");
                System.out.println(book);
                return;
            }
        }

        bookList.addBook(addBook);

        bookList.setUsedSize(currentUsedSize + 1);
    }

}
